﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using TencentWeiboSDK.Model;
using TencentWeiboSDK.Services.Util;
using TencentWeiboSDK.Hammock;
using System.Collections.Generic;
using System.Text;
using TencentWeiboSDK.Deserializer;

namespace TencentWeiboSDK.Services
{
    public class WeiboService : BaseService
    {
        /// <summary>
        /// 构造函数.
        /// </summary>
        public WeiboService():this(null)
        { }

        /// <summary>
        /// 构造函数.
        /// </summary>
        /// <param name="accessToken">
        /// 指示该 Service 所需要的 AccessToken，优先级高于 OAuthConfigruation.AccessToken, 若该值为 null,
        /// SDK 将默认使用 OAuthConfigruation.AccessToken.
        /// </param>
        public WeiboService(AccessToken accessToken)
            : base(accessToken)
        { }


        /// <summary>
        /// 转发一条微博.
        /// </summary>
        /// <param name="argment">参数列表.</param>
        /// <param name="callback">回调返回空.</param>
        public void Repost(ServiceArgument argment, Action<Callback<object>> callback)
        {
            this.Post("t/re_add", argment, (request, response, userState) =>
            {
                if (null != callback)
                {
                    InternalCallback(response, callback);
                }
            });
        }

        private void InternalCallback(RestResponse response, Action<Callback<object>> action)
        {
            lock (this)
            {
                List<User> list = null;

                BaseDeserializer serializer = DeserializerManager.Instance.BuildUserDeserializer();
                list = serializer.ReadList(response.Content) as List<User>;

                if (null != action)
                {
                    //action(new Action<Callback<object>>);
                }
            }
        }
    }
}
